<?php

namespace App\Http\Controllers\Admin\Imlooke;

use Illuminate\Http\Request;
use App\Models\API\Activity;
use App\Models\API\ActivityComment;
use App\Http\Controllers\Controller;

class ActivityController extends Controller
{
    public $module = 'activities';

    public $parent_module;

    public $breadcrumb_name = 'activities';

    public $page_name = 'Imlooke管理';

    public $page_describe = '活动管理';

    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $activities = Activity::join('users', 'activities.user_id', '=', 'users.id')
        ->select('activities.*', 'users.user_name')
        ->withCount('activityApply', 'activityJoin', 'activityComment')
        ->paginate();
        return view('imlooke.activities.index', compact('activities'));
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        $activity = Activity::find($id)
        ->join('users', 'activities.user_id', '=', 'users.id')
        ->select('activities.*', 'users.user_name')
        ->withCount('activityApply', 'activityJoin', 'activityComment')
        ->first();

        $comments = ActivityComment::where('activity_id', $id)
        ->orderBy('created_at', 'desc')
        ->join('users', 'activity_comments.user_id', '=', 'users.id')
        ->select('activity_comments.*', 'users.user_name', 'users.user_img')
        ->paginate(5);

        return view('imlooke.activities.show', compact('activity', 'comments'));
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        
    }
}
